//
//  NQAddRecordBtn.m
//  ZLFastDoctor
//
//  Created by 李岚清 on 16/5/24.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "NQAddRecordBtn.h"

@interface NQAddRecordBtn ()

@property (nonatomic, strong) UIView *lineView;

@end

@implementation NQAddRecordBtn

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.lineView];
    }
    return self;
}

- (void)setHighlighted:(BOOL)highlighted {}

/**
 *  布局子控件的frame
 */
- (void)layoutSubviews {
    [super layoutSubviews];
    
    // 获得按钮的宽高
    CGFloat buttonW = self.frame.size.width;
    CGFloat buttonH = self.frame.size.height;
    // 获得图片的宽度
    CGFloat imageW = self.imageView.frame.size.width;
    CGFloat imageH = self.imageView.frame.size.height;
    
    CGFloat margin = 10;
    // 再调整图片和titleLabel的位置
    CGFloat labelW = self.titleLabel.frame.size.width;
    CGFloat labelH = self.titleLabel.frame.size.height;
    
    // 计算image的x值
    CGFloat imageX = (buttonW - labelW - margin - imageW) * 0.5;
    self.imageView.frame = CGRectMake(imageX, (buttonH - imageH) * 0.5, labelH, labelH);
    
    self.titleLabel.frame = CGRectMake(CGRectGetMaxX(self.imageView.frame) + margin, (buttonH - labelH) * 0.5, labelW, labelH);
    
    self.lineView.frame = CGRectMake(0, 0, buttonW, 0.4);
    
}

- (UIView *)lineView {
    if (_lineView == nil) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor lightGrayColor];
    }
    return _lineView;
}


@end
